package com.eling.elcms.community.webapp.controller;

import com.eling.elcms.community.model.Organization;
import com.eling.elcms.community.model.Organization.Status;
import com.eling.elcms.community.service.IOrganizationManager;
import com.eling.elcms.core.AppContext;
import com.eling.elcms.core.webapp.controller.BaseFormController;
import com.eling.elcms.core.webapp.controller.Msg;
import com.eling.elcms.core.webapp.spring.ModelFilling;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;
import java.util.List;

@Controller
public class OrganizationController extends BaseFormController{
    @Autowired
    private IOrganizationManager organizationManager;

    @RequestMapping("/api/organization/add")
    @ResponseBody
    public Organization add(@ModelAttribute Organization user) {
    	return organizationManager.save(user);
    }
    
    @RequestMapping("/api/organization/{pkOrganization}/delete")
    
    @ResponseBody
    public Msg delete(@PathVariable Long pkOrganization) {
    	organizationManager.remove(pkOrganization);
    	return new Msg("删除成功");
    }
    
    @RequestMapping("/api/organization/query")
    @ResponseBody
    public List<Organization> query(@ModelAttribute Organization cond) {
    	return organizationManager.query(cond);
    }
    
    @RequestMapping("/api/organization/setting")
    @ResponseBody
    public Organization setting(@ModelAttribute@ModelFilling Organization agency) {
    	agency.setStatus(Status.Setting);
    	agency.setEnableTime(new Date());
    	return organizationManager.save(agency);
    }
    
    @RequestMapping("/api/organization/blockup")
    @ResponseBody
    public Organization blockUp(@ModelAttribute@ModelFilling Organization agency) {
    	agency.setStatus(Status.BlockUp);
    	agency.setDisableTime(new Date());
    	return organizationManager.save(agency);
    }
    
    /**
     * vanke 接口 机构存放文件夹
     * @return
     */
    @RequestMapping("/api/organization/querytheme")
    @ResponseBody
    public String queryTheme() {
    	return organizationManager.queryTheme(AppContext.curUser().getPkUser());
    }

}
